// 配置请求方式
import axios from 'axios'
import { getToken } from '@/utils/auth'
const host = window.config.host 

// 获取验证
export const getRequestByHost = function(url, params) {
  return axios({
    params: params,
    method: 'get',
    url: `${tokenHost}${url}`,
    headers: {
      'Content-Type': "application/json;charset=utf-8",
      'Authorization': getToken(),
      'X-trustuser-access-token': localStorage.getItem('user_access_token'),
      'X-trustagw-access-token': localStorage.getItem('access_token'),
    },
  })
}

export const postRequest = function(url, params) {
  return axios({
    data: params,
    method: 'post',
    url: `${host}${url}`,
    headers: {
      'Content-Type': "application/json;charset=utf-8",
      'Authorization': getToken(),
    },
  })
}

export const getRequest = function(url, params) {
  return axios({
    params: params,
    method: 'get',
    url: `${host}${url}`,
    headers: {
      'Content-Type': "application/json;charset=utf-8",
      'Authorization': getToken(),
    },
  })
}

// post请求下载文件
export const dwRequest = (url, params) => {
  return axios({
    method: 'post',
    url: `${host}${url}`,
    responseType: 'blob',
    data: params,
    headers: {
      'Authorization': getToken(),
      'X-trustuser-access-token': localStorage.getItem('user_access_token'),
      'X-trustagw-access-token': localStorage.getItem('access_token'),
    },
  })
}
